#include "lvgl/lvgl.h"
#include "lv_new.h"

lv_style_t * style;
lv_obj_t * scr ;

lv_obj_t * btn1 ;
lv_obj_t * btn2 ;
lv_obj_t * label1 ;
lv_obj_t * label2 ;
lv_obj_t * label3 ;
lv_obj_t * led;
lv_obj_t * gauge;
lv_obj_t * slider;

static void slider_event_cb(lv_obj_t *obj,lv_event_t event)
{
    switch (event) {
    case LV_EVENT_VALUE_CHANGED:
        lv_label_set_text_fmt(label1,"%d",lv_slider_get_value(slider));
        break;
    case LV_EVENT_LONG_PRESSED:
        lv_obj_set_drag(slider,true);
        lv_obj_align(label1,slider,LV_ALIGN_OUT_BOTTOM_MID,0,0);
        break;
    default:
        lv_obj_set_drag(slider,false);
        break;
    }
}
void lv_new_test(void)
{



    scr = lv_scr_act();
    lv_scr_load(scr);


    btn1 = lv_btn_create(scr,NULL);
    btn2 = lv_btn_create(scr,NULL);

//    label1 = lv_label_create(btn1,NULL);
//    label2 = lv_label_create(btn2,NULL);
//    label3 = lv_label_create(scr,NULL);
//    lv_label_set_text(label3,"statdy");
//    gauge = lv_gauge_create(scr,NULL);
//    lv_gauge_set_scale(gauge,350,35,5);

//    lv_btn_set_checkable(btn1,true);
//    lv_obj_set_pos(btn1,100,100);
//    lv_label_set_text(label1,"ON/OFF");
//    led = lv_led_create(scr,NULL);
//    lv_obj_set_pos(led,300,100);
//    lv_led_set_bright(led,255);
//    lv_obj_set_pos(btn2,500,100);
//    lv_label_set_text(label2,"state");
//    lv_obj_set_event_cb(btn1, btn1_event_cb);

    slider = lv_slider_create(scr,NULL);
    label1 = lv_label_create(scr,NULL);
    lv_obj_set_pos(slider,100,200);
    lv_label_set_text(label1,"0");
    lv_obj_align(label1,slider,LV_ALIGN_OUT_BOTTOM_MID,0,0);
    lv_obj_set_event_cb(slider,slider_event_cb);

    lv_obj_set_drag(btn1,true);
    lv_obj_set_drag(btn2,true);


}

static void btn1_event_cb(lv_obj_t *obj,lv_event_t event)
{
    static uint8_t en = 0;
    switch (event) {
    case LV_EVENT_PRESSED:

        lv_led_toggle(led);
//        lv_label_set_text(label,"Button1 pressed.");
        lv_label_set_text_static(label3,"Button1 pressed.");
        break;
     case LV_EVENT_RELEASED:
        lv_obj_set_drag(btn1,false);
        lv_label_set_text(label3,"Button1 released.");

        break;
    case LV_EVENT_LONG_PRESSED:
        lv_obj_set_drag(btn1,true);
       lv_label_set_text(label3,"Button1 drag enable.");

       break;
    default:
        break;
    }

}
